import java.util.Scanner;

public class Login {
    private String userName = "name";
    private String password = "123456";
    public void login(String name,String password) throws UsernameError,PasswordError{
        if(!name.equals(this.userName)){
            throw new UsernameError("用户名错误!");
        }
        if(!password.equals(this.password)){
            throw new PasswordError("密码错误!");
        }
        System.out.println("登录成功!");
    }

    public static void main(String[] args) {
        Scanner scanner = null;
        try {
            System.out.println("请输入用户名:");
            scanner = new Scanner(System.in);
            String username = scanner.nextLine();
            System.out.println("请输入密码:");
            String password = scanner.nextLine();
            Login login1 = new Login();
            login1.login(username, password);
        } catch (UsernameError usernameError) {
            usernameError.printStackTrace();
        } catch (PasswordError passwordError) {
            passwordError.printStackTrace();
        } finally {
            scanner.close();
        }
    }

}
